package com.lagou.edu.util;

import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import reactor.core.publisher.Mono;

import java.nio.charset.StandardCharsets;

/**
 * @author 赵虎
 * @date 2021/2/23 1:01 上午
 */
public class ResponseUtil {

    protected Mono<Void> responseStatusAndMessage(ServerHttpResponse response, HttpStatus httpStatus, String message) {
        byte[] data = message.getBytes(StandardCharsets.UTF_8);
        DataBuffer buffer = response.bufferFactory().wrap(data);
        response.setStatusCode(httpStatus);
        response.getHeaders().add("Content-Type", "text/html;charset=UTF-8");
        return response.writeWith(Mono.just(buffer));
    }
}
